
import {  ipcMain } from "electron"
let timer: number = 0
let timerInterval: NodeJS.Timeout

// 开始计时事件
ipcMain.handle('start-timer', (event, value) => {
	// 计时器
	timer = value
	timerInterval = setInterval(() => {
		timer--
		if (timer <= 0) {
			clearInterval(timerInterval)
			timer = 0
		}
		// 发送更新事件
		event.sender.send('update-timer', timer)
	}, 1000) as NodeJS.Timeout
})

// 暂时计时事件
ipcMain.handle('stop-timer', () => {
	if (timerInterval) {
		clearInterval(timerInterval)
	}
})

